<template>
	<view>
		<view class="tow">
			<view class="row" v-for="item in userArr" :key="item._id">
				<view>姓名：{{item.name}} </view>
				<view>手机：{{item.tel}} </view>
				<view>年龄：{{item.age}} </view>
				<view v-for="(i,index) in  item.interest" :key="index">
					{{`${item.name}：在${i} 点击了修改`}}
				</view>
			 </view>
			 <button type="primary" @click="onUPdate">修改</button>
			 <button style="margin-top: 20rpx;" type="warn" @click="onRemove">删除</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
			userArr:[]
			}
		},
		onLoad() {
		console.log("首页加载")
		this.getUser()
		},
		onHide() { 
		console.log("首页隐藏")
		},
		methods: {
		getUser(){
			uniCloud.callFunction({
				name:"cloudDemoUser",
			}).then(res=>{
				console.log(res.result.data,"获取用户列表")
				if(res && res.result.data.length > 0)
				this.userArr=res.result.data
			})
		},
		//修改
		onUPdate(){
			uni.showLoading({
				title:"修改中"
			})
			uniCloud.callFunction({
				name:"cloudUserUp",
				data:{
				_id:"667248628620667bb4261be9",
				}
			}).then(res=>{
				if(res.result.msg === 0){
					this.getUser()
					uni.hideLoading()
				}
			})
		},
		//删除
		onRemove(){
			uniCloud.callFunction({
				name:"cloudUserRemove",
				data:{
				_id:"667248628620667bb4261be9",
				}
			}).then(res=>{
				console.log(res)
				this.getUser()
			})
		}
		
		},
		
	}
</script>

<style lang="scss">
	.tow{
		padding: 0 30rpx;
		.row{
			padding: 30rpx 0;
			border-bottom: 1rpx solid #ccc;
			display: flex;
			flex-direction: column;
			justify-content: space-around;
			
		}
	}
</style>
